import tinymce from 'tinymce/tinymce'
import { handleSave } from '../docSave/plugin'

function closePage() {
  // TODO
}
tinymce.PluginManager.add('docClose', function (editor) {
  editor.ui.registry.addMenuItem('docClose', {
    text: '关闭',
    onAction: async function () {
      if (tinymce.activeEditor.isDirty()) {
        tinymce.activeEditor.windowManager.confirm('编辑器页面有未保存的内容，是否保存？', async (state) => {
          if (!!state) {
            await handleSave()
            closePage()
          }
        })
      } else {
        closePage()
      }
    }
  })

  return {
    getMetadata: function () {
      return {
        name: '关闭',
        url: 'http://sfrj.cn'
      }
    }
  }
})
